var ztreeCallback = {
    onClick: function (event, treeId, treeNode) {
        $("#fname").html(treeNode.name);
        $("#fsize").html(convertSize(treeNode.size));
        $("#furl").html(treeNode.downloadUrl);
    },
    onRightClick: function (event, treeId, treeNode) {
        let x=event.clientX;//左距离
        let y=event.clientY;//右距离
        let scrolltop=document.documentElement.scrollTop || document.body.scrollTop;//滚动条向下滚动距离
        let scrollleft=document.documentElement.scrollLeft || document.body.scrollLeft;//滚动条向左滚动距离
        let left = x+scrollleft
        let top = y + scrolltop
        if (!treeNode && event.target.tagName.toLowerCase() != "button" && $(event.target).parents("a").length == 0) {
            zTree.cancelSelectedNode();
            showRMenu("root", left, top);
        } else if (treeNode && !treeNode.noR) {
            zTree.selectNode(treeNode);
            showRMenu("node", left, top);
        }
    },
    beforeDrop: function (treeId, treeNodes, targetNode, moveType) {
        if (moveType === 'inner') {
            return targetNode.isParent;
        } else {
            return targetNode.parentNode ? (targetNode.parentNode.isParent) : true
        }

    },
    onDrop: function (event, treeId, treeNodes, targetNode, moveType) {
        let srcNodeIds = [];
        let targetNodeId = targetNode.id;
        for (let i = 0; i < treeNodes.length; i++) {
            srcNodeIds.push(treeNodes[i].id)
        }
        if (moveType !== "inner") {
            targetNodeId = targetNode.pId
        }
        console.log("移动" + srcNodeIds + "--" + targetNodeId)
        $.ajax({
            url: "/gofile/move",
            contentType: "application/json",
            dataType: "json",
            type: 'POST',
            data: JSON.stringify({ src_paths: srcNodeIds, dist_path: targetNodeId }),
            success: function (data) {
                if (data.success) {
                    alert("移动成功")
                    zTree.reAsyncChildNodes(null, "refresh")
                } else {
                    alert("移动失败")
                }
            }
        })
    }
}
